package com.ruoyi.meetingroom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.TenantContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.meetingroom.domain.MeetingRoom;
import com.ruoyi.meetingroom.service.IMeetingRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 会议室信息Controller
 *
 * @author ruoyi
 */
@Api(tags = "会议室信息管理")
@RestController
@RequestMapping("/meetingroom/room")
public class MeetingRoomController extends BaseController
{
    @Autowired
    private IMeetingRoomService meetingRoomService;

    /**
     * 查询会议室信息列表
     */
    @ApiOperation("查询会议室信息列表")
    @PreAuthorize("@ss.hasPermi('meetingroom:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeetingRoom meetingRoom)
    {
        startPage();
        List<MeetingRoom> list = meetingRoomService.selectMeetingRoomList(meetingRoom);
        return getDataTable(list);
    }

    /**
     * 导出会议室信息列表
     */
    @ApiOperation("导出会议室信息列表")
    @PreAuthorize("@ss.hasPermi('meetingroom:room:export')")
    @Log(title = "会议室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingRoom meetingRoom)
    {
        List<MeetingRoom> list = meetingRoomService.selectMeetingRoomList(meetingRoom);
        ExcelUtil<MeetingRoom> util = new ExcelUtil<MeetingRoom>(MeetingRoom.class);
        util.exportExcel(response, list, "会议室信息数据");
    }

    /**
     * 获取会议室信息详细信息
     */
    @ApiOperation("获取会议室信息详细信息")
    @PreAuthorize("@ss.hasPermi('meetingroom:room:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(meetingRoomService.selectMeetingRoomByRoomId(roomId));
    }

    /**
     * 新增会议室信息
     */
    @ApiOperation("新增会议室信息")
    @PreAuthorize("@ss.hasPermi('meetingroom:room:add')")
    @Log(title = "会议室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingRoom meetingRoom)
    {
        meetingRoom.setCreateBy(getUsername());
        return toAjax(meetingRoomService.insertMeetingRoom(meetingRoom));
    }

    /**
     * 修改会议室信息
     */
    @ApiOperation("修改会议室信息")
    @PreAuthorize("@ss.hasPermi('meetingroom:room:edit')")
    @Log(title = "会议室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingRoom meetingRoom)
    {
        meetingRoom.setUpdateBy(getUsername());
        return toAjax(meetingRoomService.updateMeetingRoom(meetingRoom));
    }

    /**
     * 删除会议室信息
     */
    @ApiOperation("删除会议室信息")
    @PreAuthorize("@ss.hasPermi('meetingroom:room:remove')")
    @Log(title = "会议室信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(meetingRoomService.deleteMeetingRoomByRoomIds(roomIds));
    }
} 